﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Dundas.Charting.WebControl;
using DQYT.HTDZ.BLL;
using System.Data;
using DQYT.HTDZ.Model;
using DQYT.HTDZ.DBUtility;
using DQYT.HTDZ.Common;
using System.Reflection;
using DQYT.HTDZ.BusinessService;
using System.Threading;
using System.Xml;
using System.IO;
using System.Text;
namespace DQYT.HTDZ.Web.Views.DRAW
{
    /// <summary>
    /// 描图模块的后台类，主要实现一些控件的数据初始化和逻辑
    /// </summary>
    public partial class DrawMult1 : System.Web.UI.Page
    {
        private string cjrq_s;//采集日期范围的最小值
        private string cjrq_e;//采集日期范围的最大值
        private string selectWellid;//单井的井号
        private DataTable drawTb;//保存时间段中查询出的数据
        private DataTable currentTb = new DataTable();//临时数据表
        private BDDATESOURSEBLL dataSourseBll = new BDDATESOURSEBLL();
        private DrawFunc drawFunc = new DrawFunc();//描图类
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                initDdlWellID();//初始化ddl列表中的井号
                initGridview();//初始化gridview
                initTime();
               
                
            }

        }
        /// <summary>
        /// 检索日期区间内的井数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            if (this.txtTs.Text == "" || this.txtTe.Text == "")
            {
                JScript.Alert(this.Page, "请您选择时间段");
            }
            else
            {
                transTime();//转换txt中的日期格式
                this.cjrq_s = this.txtTs.Text;
                this.cjrq_e = this.txtTe.Text;
                this.selectWellid = this.ddllwellid.SelectedValue;//井号列表中当前选中的井号
                if (this.drawTb != null)
                    this.drawTb.Clear();
                if (this.checkIsWellid.Checked == true)
                {
                    //通过日期和井号检索
                    this.drawTb = drawFunc.getWellList_DateAndID(this.cjrq_s, this.cjrq_e, this.selectWellid);
                }
                else
                {
                    //通过日期检索
                    this.drawTb = drawFunc.getWellList_Date(this.cjrq_s, this.cjrq_e);
                }
                this.Session.Add("drawTable", this.drawTb);//将表保存起来
                initCheckBoxList();
            }
        }
        /// <summary>
        /// 初始化检索出的井号、日期列表
        /// </summary>
        protected void initCheckBoxList()
        {
           
            List<DataViewList> viewList = new List<DataViewList>();
            this.drawTb = (DataTable)this.Session["drawTable"];
            for (int i = 0; i < this.drawTb.Rows.Count; i++)
            {
                DataViewList view = new DataViewList();
                view.TxtWellid = this.drawTb.Rows[i][1].ToString();
                view.TxtJcrq = this.drawTb.Rows[i][2].ToString();
                view.Dvalue = this.drawTb.Rows[i][0].ToString();
                viewList.Add(view);
            }
            this.GridView1.DataSource = viewList;
            this.GridView1.DataBind();
        }
        /// <summary>
        /// 进入页面初始化gridview
        /// </summary>
        public void initGridview()
        {
            this.drawTb = drawFunc.getcurdata();
            this.Session.Add("drawTable", this.drawTb);//将表保存起来
            initCheckBoxList();
        }

        /// <summary>
        /// 转换日期控件中的日期格式，变为与数据库中匹配的
        /// </summary>
        protected void transTime()
        {
            string timeS = this.txtTs.Text;
            string timeE = this.txtTe.Text;
            int i = timeS.IndexOf("/", 3, timeS.Length - 3);
            string ts = timeS.Substring(i, 5);
            timeS = timeS.Replace(ts, "");
            timeS = ts.Substring(1, 4) + "/" + timeS;
            this.txtTs.Text = timeS;

            int j = timeE.IndexOf("/", 3, timeE.Length - 3);
            string te = timeE.Substring(j, 5);
            timeE = timeE.Replace(te, "");
            timeE = te.Substring(1, 4) + "/" + timeE;
            this.txtTe.Text = timeE;
        }
        /// <summary>
        /// 初始化井号选择列表
        /// </summary> 
        protected void initDdlWellID()
        {
            DataTable dt = new DataTable();
            dt = drawFunc.getWellidList();
            this.ddllwellid.Items.Clear();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                ListItem item = new ListItem();
                item.Text = dt.Rows[i][0].ToString();
                item.Value = dt.Rows[i][0].ToString();
                this.ddllwellid.Items.Add(item);
                this.ddllwellid.DataBind();
            }

        }
        /// <summary>
        /// 初始化时间选择框
        /// </summary>
        protected void initTime() {
            DataTable dt = new DataTable();
            dt = drawFunc.getcurJCRQ();
            if (dt.Rows.Count > 0)
            {
                this.txtTs.Text = dt.Rows[0][0].ToString();
                this.txtTe.Text = dt.Rows[1][0].ToString();
            }
            else
            {
                this.txtTs.Text = DateTime.Now.ToLongDateString();
                this.txtTe.Text = DateTime.Now.ToLongDateString();
            }
        }

        protected void ChangePage(object sender, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            //#region
            AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            //FpSpread1.GotoPage(e.NewPageIndex - 1);
            ////数据统计
            //SetPageData();
            //#endregion
        }



    }

    /// <summary>
    /// 前台存放井号和检测日期的类
    /// </summary>
    public class DataViewList
    {
        private string txtWellid;//GridView显现出来的井号
        private string txtJcrq;//GridView显现出来的检测日期
        private string dvalue;//GridView存储的值

        public string TxtWellid
        {
            get { return txtWellid; }
            set { txtWellid = value; }
        }
        public string TxtJcrq
        {
            get { return txtJcrq; }
            set { txtJcrq = value; }
        }
        public string Dvalue
        {
            get { return dvalue; }
            set { dvalue = value; }
        }
    }

}
